<%--
    Document   : index
    Created on : 12.02.2010, 22:48:51
    Author     : Morfant
--%>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="stud.cp.user.valueobjects.Property"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java"%>

<html>
    <%@include file="/header.jsp" %>
    <script type="text/javascript">
        var is_checked  = false;
        function isAnyChecked(f) {
            for (var i=0; i<f.elements.length; i++) {
                if (f.elements[i].type == "checkbox" && f.elements[i].checked)
                    return true;
            }
            return false;
        }
        function enableSubmit(chBox) {
            var f   = chBox.form;
            if (chBox.checked)
                is_checked = true;
            else
                is_checked = isAnyChecked(f)
            f.elements["confirmButton"].disabled   = is_checked ? false : true;
        }
    </script>
    <body>
        <div class="page">
            <%@include file="/cap.jsp" %>
            <div id="main">
                <h2>Список доступных для добавления свойств</h2>
                <%Integer weapon_type_id = (Integer) request.getAttribute(PluginConst.WEAPON_TYPE_ID);
                            if (weapon_type_id != null) {%>
                <form action="<%= response.encodeURL("weapon-type-action.do")
                                        + "?"
                                        + PluginConst.SUBACTION
                                        + "="
                                        + PluginConst.ADD_PROPERTIES_TO_WEAPON_TYPE
                                        + "&"
                                        + PluginConst.WEAPON_TYPE_ID
                                        + "="
                                        + weapon_type_id%>"
                      method="post"
                      name="<%= PluginConst.FORM_NAME%>">
                    <% List<Property> list =
                                                            (List<Property>) request.getAttribute(PluginConst.PROPERTIES_LIST);
                                                    if ((list != null) && (list.size() > 0)) {%>
                    <table>
                        <tr>
                            <th>
                            </th>
                            <th>
                                Имя свойства
                            </th>
                            <th>
                                Тип
                            </th>
                            <th>
                                Группа
                            </th>
                        </tr>
                        <%for (Property item : list) {%>
                        <tr>
                            <td>
                                <input
                                    type="checkbox"
                                    name="<%=PluginConst.PROPERTIES_ID%>"
                                    value="<%=item.getProperty_id()%>"
                                    onclick="enableSubmit(this);"
                                    />
                            </td>
                            <td>
                                <%= item.getName()%>
                            </td>
                            <td>
                                <%= item.getPropertyTypeName()%>
                            </td>
                            <td>
                                <%= item.getPropertyGroupName()%>
                            </td>
                        </tr>
                        <%}%>
                    </table>
                    <p>
                        <input name="confirmButton" type="submit" value="Добавить" disabled/>
                    </p>
                </form>
                <%}%>
                <div id="weaponmenucontainer">
                    <ul id="weaponmenu">
                        <li><a href="<%= response.encodeURL("weapon-type-action.do")
                                                + "?"
                                                + PluginConst.SUBACTION
                                                + "="
                                                + PluginConst.GET_WEAPON_TYPE_PROPERTIES_LIST
                                                + "&"
                                                + PluginConst.WEAPON_TYPE_ID
                                                + "="
                                                + weapon_type_id%>">Вернуться к списку свойств</a></li>
                    </ul>
                </div>
                <%}%>
            </div>
        </div>
    </body>
</html>
